/**
 * Created by Alex on 16/12/31.
 */
'use strict'

const mongoose = require('mongoose')
const Restaurant = mongoose.model('Restaurant')
const Interesting = mongoose.model('Interesting')

exports.gathered = function* (next) {
  let {gathered, id, type} = this.query
  let newGathered = gathered === '0' ? false : true
  if (!id || !type || !gathered) {
    this.body = {
      msg: 'params is require',
      data: [],
      code: 201
    }
    return
  }
  let data = null
  if (type === '1') {
    data = yield Interesting
      .update({_id: id}, {
        $set: {
          gathered: newGathered
        }
      })
  } else if (type === '2') {
    data = yield Restaurant
      .update({_id: id}, {
        $set: {
          gathered: newGathered
        }
      })
  } else {
    this.body = {
      msg: 'type is not exist',
      data: [],
      code: 201
    }
    return
  }
  this.body = {
    msg: 'success',
    data,
    code: 1
  }
}